package com.spider.moudle.main;

import com.spider.moudle.api.realize.StandardLogRecorder;
import com.spider.moudle.consumer.StandardTestConsumer;
import com.spider.moudle.entity.Setting;
import com.spider.moudle.pool.CrawlerPool;
import com.spider.moudle.producer.StandardProducer;
import com.spider.moudle.util.CenterExecutorUtil;
import com.spider.moudle.util.SettingsUtil;

import java.io.IOException;

/**
 * 测试单个爬虫网站的主方法
 */
public class TestMain {

    static void test() throws IllegalAccessException, ClassNotFoundException, InstantiationException {
        String site = "TianYa";
        System.out.println("=================  这里是  " + site +" 的测试方法  ======================");
        /**
         * 这个是每个网站的个性化配置，是从settings.json里面读取到的(必须)
         */
        Setting setting = SettingsUtil.getSettingBySite(site);
        //初始化crawler pool 先读取配置文件判读该网站是否加入主线程工作，
        CrawlerPool.getInstance().initialItem(setting);
        StandardLogRecorder.getInstance().initialize();

        //生成任务
        CenterExecutorUtil.execute(new StandardProducer(setting));
        //消费任务
        CenterExecutorUtil.execute(new StandardTestConsumer(setting));
    }

    public static void main(String[] args) throws Exception {
        test();
    }
}
